import QtQuick 2.2
import QtGraphicalEffects 1.0

Rectangle {
    id: login
    width: 400
    height: 250
    radius: 5
    clip: true
    //color: "#15A0F5"

    MouseArea {
        id: dragRegion
        anchors.fill: parent
        property point clickPos: "0,0"
        onPressed: {
            clickPos  = Qt.point(mouse.x,mouse.y)
        }
        onPositionChanged: {
            //鼠标偏移量
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            //如果mainwindow继承自QWidget,用setPos
            mainlogin.setX(mainlogin.x+delta.x)
            mainlogin.setY(mainlogin.y+delta.y)
        }
    }

    Item {
        id: rootBox
        anchors.top: parent.top
        width: parent.width
        height: 45
        property int radius: 5

        signal close

        onClose: mainlogin.close()

        function hideMiniWindow(){
            pinButton.active = false
            mainView.hide()
            mainView.recordCurrentVisible("false")
        }

        property int textMargin: 8

        function isPinned(){
            return pinButton.active
        }

        Rectangle {
            id: frame

            width: parent.width
            anchors.fill:parent
            radius: rootBox.radius
            clip: true

            gradient:Gradient {
                GradientStop { position: 0.8; color: "#15A0F5" }
                GradientStop { position: 0.9; color: "#FFFFFF" }
            }

            Item {
                id: title
                anchors.top: frame.top
                //anchors.verticalCenter: parent.verticalCenter
                anchors.left: frame.left
                anchors.right: frame.right
                height: 26

                ImageButton {
                    id: closeButton
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: 8
                    normal_image: "images/close_normal.png"
                    hover_image: "images/close_hover.png"
                    press_image: "images/close_press.png"
                    onClicked: rootBox.close()
                }
            }
        }
    }


    /*Image {
        id: bg
        anchors.fill: parent
        //fillMode: Image.PreserveAspectCrop
        source: "../../icon/bg/TT.jpg"
    }*/


    signal login(string account, string password)

    LineInput{
        id: accountInput
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        anchors.verticalCenterOffset: -30
        texttype: "账户"
    }

    LineInput{
        id: passwordInput
        anchors{
            top: accountInput.bottom
            topMargin: 10
            left: accountInput.left
            right: accountInput.right
        }
        echoPassword: true
        texttype: "密码"
    }
    Button {
        id: loginButton
        anchors.topMargin: 20
        anchors.top: passwordInput.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        border.color: "gray"
        textSize: 15
        text:"login"

        onClicked: {
            login.login(accountInput.text, passwordInput.text)
        }
    }
}
